#!/bin/bash

LOGFILE="$CUSTOMER-$HOSTNAME-$JOBNAME.log"
LOG="$LOGDIR/$LOGFILE"
DEBUGDIR="$LOGDIR/DEBUG"

DEBUGONSITE="$DEBUGDIR/onsite-`date +%u`-$LOGFILE.log"
DEBUGOFFSITE="$DEBUGDIR/offsite-`date +%u`-$LOGIFLE.log"
DEBUGARCHIVE="$DEBUGDIR/archive-`date +%u`-$LOGFILE.log"

MAILLOG=""

if [ ! -d "$LOGDIR" ]  ; then mkdir -p $LOGDIR; fi
if [ ! -d "$DEBUGDIR" ]; then mkdir -p $DEBUGDIR; fi

function log () {
	echo -e "`date '+%F %T'` $ME: $*" >> $LOG
    echo -e "`date '+%F %T'` $ME: $*"
    MAILLOG+="`date '+%F %T'` $ME: $* \n"
}

function send () {

    if test -z "$MAILFROM"; then MAILFROM="backuper@rtimemachine.local"; fi

    if ! test -z "$MAILTO"
    then
        MAILHEADER=""
        MAILHEADER+="From: $MAILFROM \n"
        MAILHEADER+="To: $MAILTO \n"
        MAILHEADER+="Subject: Backup HOST `cat /etc/hostname` TYPE $ME JOB $JOBNAME STATUS $1\n\n"

        echo -e $MAILHEADER""$MAILLOG | /usr/lib/sendmail -t
    fi
}    
